package main

import "golang.org/x/net/context"
import (
	pb "wiloon.com/nj4xx-calc/proto"
	"log"
	"net"
	"google.golang.org/grpc/reflection"
	"google.golang.org/grpc"
	"time"
)

const (
	address = ":7000"
)

type Server struct {
}

func (server *Server) Calculate(ctx context.Context, in *pb.Nj4XxRequest) (*pb.Nj4XxReply, error) {
	log.Println("request:", time.Now())
	return &pb.Nj4XxReply{Reply: true}, nil
}
func main() {
	log.Println("server starting...")

	lis, err := net.Listen("tcp", address)
	if err != nil {
		log.Fatalf("failed to listen: %v", err)
	}
	log.Println("listen:" + address)

	s := grpc.NewServer()
	pb.RegisterNj4XxServer(s, &Server{})
	reflection.Register(s)
	if err := s.Serve(lis); err != nil {
		log.Fatalf("failed to serve: %v", err)
	}
}
